package me.ywy.kotlinvideo.adapter

import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import me.ywy.kotlinvideo.widget.HomeItemView
import me.ywy.kotlinvideo.widget.LoadMoreView

/**
 * Created by ywy on 2018-11-06.
 */
class HomeAdapter: RecyclerView.Adapter<HomeAdapter.HomeHolder>() {

    var pageTotal = 20

    fun loadMore(addNum:Int){
        pageTotal += addNum
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeHolder {
        if(viewType == 1){
            return HomeHolder(HomeItemView(parent.context))
        }else{

            return HomeHolder(LoadMoreView(parent.context))
        }
    }

    override fun getItemCount(): Int {
        return pageTotal + 1
    }

    override fun onBindViewHolder(holder: HomeHolder, position: Int) {

    }

    class HomeHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) {

    }

    override fun getItemViewType(position: Int): Int {
        if(position < pageTotal){
            return 1
        }else{
            return 2
        }
    }


}